<template>
	<view class="health-detail-container">
		<!-- 顶部基本信息区域 -->
		<view class="header">
			<image :src="avatar" class="pet-avatar"></image>
			<view class="pet-info">
				<text class="pet-detail">{{petType}} | {{petAge}}岁</text>
				<text class="pet-name">{{petName}}</text>
			</view>

			<view class="back-btn" @click="goBack">
				<image src="/static/back.png" mode="aspectFill" class=""></image>
			</view>
		</view>

		<!-- 健康概览 -->
		<view class="health-overview">
			<view class="section-title">
				<text class="title-text">健康概览</text>
			</view>
			<view class="health-metrics">
				<view class="metric-item" v-for="(item, index) in healthMetrics" :key="index">
					<view class="metric-icon">
						<image :src="item.icon" class="iconfont" mode="aspectFill"></image>
					</view>
					<view class="metric-content">
						<text class="metric-label">{{item.label}}</text>
						<text class="metric-value">{{item.value}}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 体检记录 -->
		<view class="examination-record">
			<view class="section-title">
				<text class="title-text">体检记录</text>
				<!-- <text class="more-link" @click="navigateToAllRecords">查看全部 ></text> -->
			</view>
			<view class="record-list">
				<view class="record-item" v-for="(item, index) in examinationRecords" :key="index"
					@click="viewRecordDetail(item)">
					<view class="record-date">
						<text class="date-day">{{item.day}}</text>
						<text class="date-month">{{item.month}}</text>
					</view>
					<view class="record-content">
						<text class="record-title">{{item.title}}</text>
						<text class="record-hospital">{{item.hospital}}</text>
						<view class="record-status" :class="getStatusClass(item.status)">{{item.status}}</view>
					</view>
					<text class="record-arrow">></text>
				</view>
			</view>
		</view>

		<!-- 健康问题 -->
		<view class="health-issues" v-if="healthIssues.length > 0">
			<view class="section-title">
				<text class="title-text">健康问题</text>
			</view>
			<view class="issues-list">
				<view class="issue-item" v-for="(item, index) in healthIssues" :key="index">
					<view class="issue-tag" :style="{backgroundColor: item.tagColor}">{{item.tag}}</view>
					<view class="issue-content">
						<text class="issue-title">{{item.title}}</text>
						<text class="issue-desc">{{item.description}}</text>
						<view class="issue-solution" v-if="item.solutions.length > 0">
							<text class="solution-title">建议解决方案：</text>
							<view class="solution-tags">
								<text class="solution-tag" v-for="(solution, sIndex) in item.solutions"
									:key="sIndex">{{solution}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 健康日志 -->
		<view class="health-logs">
			<view class="section-title">
				<text class="title-text">健康日志</text>
				<text class="add-log-btn" @click="addNewLog">+ 添加记录</text>
			</view>
			<view class="log-timeline">
				<view class="log-item" v-for="(item, index) in healthLogs" :key="index">
					<view class="log-time">{{item.createTime}}</view>
					<view class="log-content">
						<text class="log-title">{{item.title}}</text>
						<text class="log-desc">{{item.content}}</text>
						<view class="log-images" v-if="item.image && item.image.length > 0">
							<image v-for="(img, imgIndex) in item.image" :key="imgIndex" :src="img" class="log-image"
								@click="previewImage(item.image, imgIndex)"></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 推荐产品 -->
		<view class="recommended-products">
			<view class="section-title">
				<text class="title-text">健康推荐</text>
			</view>
			<scroll-view scroll-x class="products-scroll" show-scrollbar="false">
				<view class="products-scroll-content">
					<view class="product-item" v-for="(item, index) in recommendList" :key="index"
						@click="viewProductDetail(item)">
						<image :src="item.image" class="product-image"></image>
						<text class="product-name">{{item.name}}</text>
						<text class="product-reason">{{item.desc}}</text>
						<text class="product-price">¥{{item.price}}</text>
						<view class="product-buy-btn">立即购买</view>
					</view>
				</view>
			</scroll-view>
		</view>

		<!-- 底部留白区域 -->
		<view class="bottom-space"></view>
	</view>
</template>

<script>
	import {
		userApi,
		productApi
	} from '../../../api/user';

	export default {
		data() {
			return {
				petName: '',
				avatar: '',
				petType: '',
				petWeight: '',
				petAge: '',
				notes: '',
				healthMetrics: [{
						label: '体重',
						value: '12.5 kg',
						icon: '/static/health/weight.png',
						history: [12.3, 12.4, 12.5],
						dates: ['2024-12-01', '2025-01-15', '2025-03-01']
					},
					{
						label: '生长发育',
						value: '38.5 °C',
						icon: '/static/health/shengzhang.png',
						history: [38.2, 38.4, 38.5],
						dates: ['2024-12-01', '2025-01-15', '2025-03-01']
					},
					{
						label: '营养状况',
						value: '75 次/分',
						icon: '/static/health/yingyang.png',
						history: [78, 76, 75],
						dates: ['2024-12-01', '2025-01-15', '2025-03-01']
					},
					{
						label: '体检建议',
						value: '良好',
						icon: '/static/health/tijian.png',
						history: ['一般', '良好', '良好'],
						dates: ['2024-12-01', '2025-01-15', '2025-03-01']
					}
				],
				examinationRecords: [{
						id: 'exam001',
						day: '15',
						month: '3月',
						title: '年度体检',
						hospital: '爱宠动物医院',
						doctor: '王医生',
						status: '正常',
						date: '2025-03-15',
						reports: [{
								type: 'blood',
								url: '/static/report1.pdf',
								name: '血液检查报告'
							},
							{
								type: 'xray',
								url: '/static/report2.pdf',
								name: 'X光检查报告'
							}
						]
					},
					{
						id: 'exam002',
						day: '20',
						month: '1月',
						title: '疫苗接种',
						hospital: '爱宠动物医院',
						doctor: '李医生',
						status: '已完成',
						date: '2025-01-20',
						reports: [{
							type: 'vaccine',
							url: '/static/report3.pdf',
							name: '疫苗接种记录'
						}]
					},
					{
						id: 'exam003',
						day: '05',
						month: '12月',
						title: '皮肤检查',
						hospital: '宠物健康中心',
						doctor: '张医生',
						status: '需关注',
						date: '2024-12-05',
						reports: [{
							type: 'skin',
							url: '/static/report4.pdf',
							name: '皮肤检查报告'
						}]
					}
				],
				healthIssues: [{
						id: 'issue001',
						tag: '营养',
						tagColor: '#F9CB43',
						title: '钙质不足',
						description: '最近检查显示钙含量低于标准值，建议补充钙质营养。',
						createdAt: '2025-03-15',
						solutions: ['钙质营养粉', '含钙零食', '调整饮食结构']
					},
					{
						id: 'issue002',
						tag: '皮肤',
						tagColor: '#FF6B35',
						title: '轻微皮肤过敏',
						description: '冬季皮肤干燥导致轻微过敏现象，需要注意保湿。',
						createdAt: '2024-12-05',
						solutions: ['宠物专用保湿喷雾', '过敏原检测', '调整洗浴用品']
					}
				],
				healthLogs: [],
				recommendList: [],
				recommendedProduct: {
					name: '',
					desc: '',
					image: '/static/pet-test.png',
					price: 0,
					id: 0
				},
				allProducts: [], // 存储所有商品数据
				userId: '',
				// 常见犬种理想体重范围(kg)
				dogWeightStandards: {
					'萨摩耶': {
						'min': 16,
						'max': 30,
						'puppy1Y': 15
					},
					'金毛': {
						'min': 25,
						'max': 34,
						'puppy1Y': 20
					},
					'拉布拉多': {
						'min': 25,
						'max': 36,
						'puppy1Y': 20
					},
					'哈士奇': {
						'min': 16,
						'max': 27,
						'puppy1Y': 15
					},
					'柯基': {
						'min': 10,
						'max': 14,
						'puppy1Y': 8
					},
					'比熊': {
						'min': 3,
						'max': 6.5,
						'puppy1Y': 3
					},
					'贵宾': {
						'min': 3,
						'max': 8,
						'puppy1Y': 3
					},
					'博美': {
						'min': 1.5,
						'max': 3.5,
						'puppy1Y': 1.5
					},
					'柴犬': {
						'min': 8,
						'max': 12,
						'puppy1Y': 7
					},
					'阿拉斯加': {
						'min': 32,
						'max': 50,
						'puppy1Y': 25
					}
				},
				// 常见猫咪理想体重范围(kg)
				catWeightStandards: {
					'英短': {
						'min': 3.5,
						'max': 7,
						'kitten1Y': 3
					},
					'美短': {
						'min': 3.5,
						'max': 7,
						'kitten1Y': 3
					},
					'暹罗': {
						'min': 2.5,
						'max': 5.5,
						'kitten1Y': 2.5
					},
					'布偶': {
						'min': 4,
						'max': 9,
						'kitten1Y': 3.5
					},
					'波斯': {
						'min': 3,
						'max': 6,
						'kitten1Y': 2.5
					},
					'缅因': {
						'min': 5,
						'max': 11,
						'kitten1Y': 4
					},
					'蓝猫': {
						'min': 3,
						'max': 6,
						'kitten1Y': 2.5
					},
					'橘猫': {
						'min': 3.5,
						'max': 7,
						'kitten1Y': 3
					},
					'加菲猫': {
						'min': 3.5,
						'max': 6.5,
						'kitten1Y': 3
					},
					'豹猫': {
						'min': 4.5,
						'max': 8.5,
						'kitten1Y': 4
					},
				}
			}
		},
		mounted() {
			// 页面加载时获取数据
			this.userId = uni.getStorageSync('userId')
			this.getPetHealthDetails();
			// 先获取所有商品，再获取宠物信息
			this.getGoods().then(() => {
				this.getPetInfo().then(() => {
					// 在获取到宠物信息后进行健康分析
					this.analyzeHealthStatus();
				})
			})
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			async getGoods() {
				try {
					const result = await productApi.getProductList()
					// 保存完整商品数据
					this.allProducts = result || []
					console.log('获取商品成功：', this.allProducts)
					return result
				} catch (error) {
					uni.showToast({
						title: '获取商品失败: ' + (error.message || '未知错误'),
						icon: 'none'
					});
					console.error('获取商品失败', error);
					return null
				}
			},
			async getPetHealthDetails() {
				try {
					const result = await userApi.getHealthRecords()
					// this.petInfo = result.data.petInfo;
					// this.healthMetrics = result.data;
					// this.examinationRecords = result.data.examinationRecords;
					// this.healthIssues = result.data.healthIssues;
					this.healthLogs = result.slice(0, 3);
					console.log(result);
					// this.recommendedProducts = result.data.recommendedProducts;
				} catch (error) {
					console.error('查询记录失败:', error);
				}
			},
			async getPetInfo() {
				try {
					const result = await userApi.getPetInfo({
						userId: this.userId
					})
					this.petName = result.petName
					this.avatar = result.avatar
					this.petType = result.petType
					this.petWeight = result.petWeight
					this.petAge = result.petAge
					this.notes = result.notes
					console.log('获取宠物信息成功：', result);
					return result;
				} catch (error) {
					uni.showToast({
						title: '获取用宠物信息失败: ' + (error.message || '未知错误'),
						icon: 'none'
					});
					console.error('获取用宠物信息失败：', error);
				}
			},
			// 在analyzeHealthStatus方法中添加健康问题生成逻辑
			analyzeHealthStatus() {
				const weight = parseFloat(this.petWeight)
				const age = parseFloat(this.petAge)
				const petType = this.petType

				// 判断是猫还是狗
				const isDog = this.isDogType(petType)
				const isCat = this.isCatType(petType)

				// 设置默认值
				this.weightStatus = '正常'
				this.nutritionStatus = '良好'
				this.growthStatus = '正常'
				this.checkupAdvice = '定期体检'

				let healthCondition = 'normal' // 用于筛选产品的健康状况标识
				let petCategory = isDog ? 'dog' : (isCat ? 'cat' : 'other')
				let ageGroup = age <= 1 ? 'young' : (age >= 7 ? 'senior' : 'adult')

				// 清空健康问题列表，准备重新生成
				this.healthIssues = []

				if (isDog) {
					healthCondition = this.analyzeDogHealth(petType, weight, age)
				} else if (isCat) {
					healthCondition = this.analyzeCatHealth(petType, weight, age)
				} else {
					// 其他宠物类型或无法识别，使用通用评估
					healthCondition = this.analyzeGenericHealth(weight, age)
				}

				// 根据健康状况生成健康问题
				this.generateHealthIssues(healthCondition, petCategory, ageGroup, age, weight)

				// 根据健康状况和宠物信息筛选推荐产品
				this.selectRecommendedProducts(healthCondition, petCategory, ageGroup)
			},
			// 新增方法：生成健康问题
			generateHealthIssues(healthCondition, petCategory, ageGroup, age, weight) {
				// 基于健康状况生成健康问题
				if (healthCondition === 'underweight') {
					this.healthIssues.push({
						id: 'issue' + Date.now(),
						tag: '营养',
						tagColor: '#F9CB43',
						title: '体重偏低',
						description: `当前体重较标准偏低，${petCategory === 'dog' ? '犬类' : '猫咪'}需要更多营养补充。`,
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['高能量营养粮', '蛋白质补充剂', '定期体重监测']
					})
				} else if (healthCondition === 'overweight') {
					this.healthIssues.push({
						id: 'issue' + Date.now(),
						tag: '体重',
						tagColor: '#FF6B35',
						title: '体重偏高',
						description: `当前体重超过健康范围，建议控制饮食并增加运动量。`,
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['低热量专用粮', '定量喂食', '增加运动时间', '避免高脂零食']
					})
				}

				// 根据年龄添加健康问题
				if (ageGroup === 'young') {
					this.healthIssues.push({
						id: 'issue' + Date.now() + 1,
						tag: '生长发育',
						tagColor: '#4A90E2',
						title: '幼龄期关键营养',
						description: `${age}岁的${petCategory === 'dog' ? '幼犬' : '幼猫'}正处于生长发育关键期，需要特别关注钙质摄入。`,
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['幼龄专用营养粮', '含钙零食', '均衡饮食']
					})
				} else if (ageGroup === 'senior') {
					this.healthIssues.push({
						id: 'issue' + Date.now() + 2,
						tag: '老年护理',
						tagColor: '#8E44AD',
						title: '老年期关节护理',
						description: `${age}岁的${petCategory === 'dog' ? '老年犬' : '老年猫'}需要更多关节保护和护理。`,
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['含氨糖软骨素成分的保健品', '老年专用配方粮', '减少剧烈运动']
					})
				}

				// 针对不同季节可能出现的问题
				const currentMonth = new Date().getMonth() + 1; // 获取当前月份(1-12)
				if (currentMonth >= 11 || currentMonth <= 2) { // 冬季
					this.healthIssues.push({
						id: 'issue' + Date.now() + 3,
						tag: '皮肤',
						tagColor: '#27AE60',
						title: '冬季皮肤保护',
						description: '冬季气候干燥，易造成皮肤问题，需注意保湿和防护。',
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['宠物专用保湿喷雾', '减少洗澡频次', '使用温和洗浴用品']
					})
				} else if (currentMonth >= 6 && currentMonth <= 8) { // 夏季
					this.healthIssues.push({
						id: 'issue' + Date.now() + 4,
						tag: '防暑',
						tagColor: '#E74C3C',
						title: '夏季防暑降温',
						description: '高温季节需注意防暑降温，预防中暑和皮肤问题。',
						createdAt: new Date().toISOString().split('T')[0],
						solutions: ['避免高温时段外出', '保持室内通风', '补充足够水分', '防晒措施']
					})
				}
			},
			isDogType(type) {
				return Object.keys(this.dogWeightStandards).some(dogType =>
						type.includes(dogType) || dogType.includes(type)) || type.toLowerCase().includes('犬') || type
					.toLowerCase().includes('狗')
			},
			isCatType(type) {
				return Object.keys(this.catWeightStandards).some(catType =>
					type.includes(catType) || catType.includes(type)) || type.toLowerCase().includes('猫')
			},
			analyzeDogHealth(petType, weight, age) {
				// 寻找最匹配的犬种标准
				let matchedType = this.findMatchingType(petType, this.dogWeightStandards)
				let healthCondition = 'normal'

				if (!matchedType) {
					// 找不到匹配品种，使用通用标准
					healthCondition = this.analyzeGenericHealth(weight, age)
					return healthCondition
				}

				const standard = this.dogWeightStandards[matchedType]

				// 针对幼犬与成犬分别处理
				if (age <= 1) {
					const expectedWeight = standard.puppy1Y
					if (weight < expectedWeight * 0.8) {
						this.setUnderweightStatus(true)
						healthCondition = 'underweight'
					} else if (weight > expectedWeight * 1.2) {
						this.setOverweightStatus(true)
						healthCondition = 'overweight'
					} else {
						this.setNormalWeightStatus(true)
						healthCondition = 'normal'
					}
				} else {
					// 成犬
					if (weight < standard.min) {
						this.setUnderweightStatus(false)
						healthCondition = 'underweight'
					} else if (weight > standard.max) {
						this.setOverweightStatus(false)
						healthCondition = 'overweight'
					} else {
						this.setNormalWeightStatus(false)
						healthCondition = 'normal'
					}
				}

				return healthCondition
			},
			analyzeCatHealth(petType, weight, age) {
				// 寻找最匹配的猫咪标准
				let matchedType = this.findMatchingType(petType, this.catWeightStandards)
				let healthCondition = 'normal'

				if (!matchedType) {
					// 找不到匹配品种，使用通用标准
					healthCondition = this.analyzeGenericHealth(weight, age)
					return healthCondition
				}

				const standard = this.catWeightStandards[matchedType]

				// 针对幼猫与成猫分别处理
				if (age <= 1) {
					const expectedWeight = standard.kitten1Y
					if (weight < expectedWeight * 0.8) {
						this.setUnderweightStatus(true)
						healthCondition = 'underweight'
					} else if (weight > expectedWeight * 1.2) {
						this.setOverweightStatus(true)
						healthCondition = 'overweight'
					} else {
						this.setNormalWeightStatus(true)
						healthCondition = 'normal'
					}
				} else {
					// 成猫
					if (weight < standard.min) {
						this.setUnderweightStatus(false)
						healthCondition = 'underweight'
					} else if (weight > standard.max) {
						this.setOverweightStatus(false)
						healthCondition = 'overweight'
					} else {
						this.setNormalWeightStatus(false)
						healthCondition = 'normal'
					}
				}

				return healthCondition
			},
			analyzeGenericHealth(weight, age) {
				// 简单通用评估逻辑
				let healthCondition = 'normal'

				if (weight <= 0 || weight > 100) {
					this.weightStatus = '数据异常'
					this.nutritionStatus = '需兽医评估'
					this.growthStatus = '需兽医评估'
					this.checkupAdvice = '建议立即体检'
					healthCondition = 'abnormal'
				} else if (weight < 3) {
					this.setUnderweightStatus(age <= 1)
					healthCondition = 'underweight'
				} else if (weight > 50) {
					this.setOverweightStatus(age <= 1)
					healthCondition = 'overweight'
				} else {
					this.setNormalWeightStatus(age <= 1)
					healthCondition = 'normal'
				}

				return healthCondition
			},
			findMatchingType(petType, standards) {
				// 尝试精确匹配
				if (standards[petType]) return petType

				// 尝试模糊匹配
				for (const standardType in standards) {
					if (petType.includes(standardType) || standardType.includes(petType)) {
						return standardType
					}
				}

				return null // 无匹配
			},
			// 修改现有的健康状态设置方法，关联健康问题
			setUnderweightStatus(isPuppy) {
				this.weightStatus = '偏瘦'
				this.nutritionStatus = '需补充营养'
				this.growthStatus = isPuppy ? '生长缓慢' : '体重不足'
				this.checkupAdvice = '建议体检评估'

				// 更新健康状态指标
				this.healthMetrics[0].value = this.petWeight + ' kg'
				this.healthMetrics[1].value = isPuppy ? '偏慢' : '正常'
				this.healthMetrics[2].value = '偏低'
				this.healthMetrics[3].value = '需体检'
			},

			setOverweightStatus(isPuppy) {
				this.weightStatus = '偏胖'
				this.nutritionStatus = '营养过剩'
				this.growthStatus = isPuppy ? '发育过快' : '需减重'
				this.checkupAdvice = '控制饮食适当运动'

				// 更新健康状态指标
				this.healthMetrics[0].value = this.petWeight + ' kg'
				this.healthMetrics[1].value = isPuppy ? '偏快' : '正常'
				this.healthMetrics[2].value = '过剩'
				this.healthMetrics[3].value = '需调整饮食'
			},

			setNormalWeightStatus(isPuppy) {
				this.weightStatus = '正常'
				this.nutritionStatus = '良好'
				this.growthStatus = isPuppy ? '发育正常' : '保持健康'
				this.checkupAdvice = '定期体检'

				// 更新健康状态指标
				this.healthMetrics[0].value = this.petWeight + ' kg'
				this.healthMetrics[1].value = '正常'
				this.healthMetrics[2].value = '良好'
				this.healthMetrics[3].value = '定期体检'
			},
			selectRecommendedProducts(healthCondition, petCategory, ageGroup) {
				if (!this.allProducts || this.allProducts.length === 0) {
					console.log('没有可用的商品数据')
					return
				}

				// 关键词映射，用于筛选产品
				const keywordMap = {
					dog: {
						underweight: ['高能量', '增强体质', '发育', '强健骨骼'],
						overweight: ['低热量', '低脂', '减重', '控制体重', '老年犬'],
						normal: ['均衡营养', '全价', '成犬', '益生菌'],
						young: ['幼犬', '奶糕', '离乳期', '发育'],
						adult: ['成犬', '成年', '全价', '全阶段'],
						senior: ['老年', '关节', '护肾', '低脂']
					},
					cat: {
						underweight: ['高能量', '增强体质', '发育', '补水'],
						overweight: ['低热量', '低脂', '减重', '控制体重', '绝育猫'],
						normal: ['均衡营养', '全价', '成猫', '毛球'],
						young: ['幼猫', '奶糕', '羊奶粉', '离乳期'],
						adult: ['成猫', '成年', '全价', '全阶段'],
						senior: ['老年猫', '关节', '护肾', '易消化']
					}
				}

				// 默认关键词，适用于无法识别的宠物类型
				const defaultKeywords = {
					underweight: ['高能量', '增强体质', '发育'],
					overweight: ['低热量', '减重', '控制体重'],
					normal: ['均衡营养', '全价']
				}

				// 确定筛选关键词
				let keywords = []

				// 添加健康状况关键词
				if (petCategory === 'dog' || petCategory === 'cat') {
					keywords = keywords.concat(keywordMap[petCategory][healthCondition] || [])
					keywords = keywords.concat(keywordMap[petCategory][ageGroup] || [])
				} else {
					keywords = keywords.concat(defaultKeywords[healthCondition] || [])
				}

				// 筛选相关产品
				let relevantProducts = this.allProducts.filter(product => {
					// 检查商品名称和描述是否包含关键词
					const productName = product.tradeName || ''
					const productDesc = product.introduction || ''

					// 筛选适合宠物类型的产品
					const isForCorrectPet = (petCategory === 'dog' && (productName.includes('犬') || productName
							.includes('狗'))) ||
						(petCategory === 'cat' && productName.includes('猫')) ||
						petCategory === 'other'

					if (!isForCorrectPet) return false

					// 检查是否包含关键词
					return keywords.some(keyword =>
						productName.includes(keyword) || productDesc.includes(keyword)
					)
				})

				// 如果找不到足够的相关产品，添加适合该宠物类型的通用产品
				if (relevantProducts.length < 3) {
					const genericProducts = this.allProducts.filter(product => {
						const productName = product.tradeName || ''

						// 筛选适合宠物类型的产品
						return (petCategory === 'dog' && (productName.includes('犬') || productName.includes(
								'狗'))) ||
							(petCategory === 'cat' && productName.includes('猫')) ||
							petCategory === 'other'
					})

					// 添加没有在relevantProducts中的产品
					for (const product of genericProducts) {
						if (!relevantProducts.find(p => p.id === product.id)) {
							relevantProducts.push(product)
							if (relevantProducts.length >= 5) break
						}
					}
				}

				// 选取主推荐产品和个性化推荐列表
				if (relevantProducts.length > 0) {
					// 主推荐产品
					const mainProduct = relevantProducts[0]
					this.recommendedProduct = {
						name: mainProduct.tradeName || '推荐产品',
						desc: mainProduct.introduction || '适合您宠物的健康产品',
						image: mainProduct.picture || '/static/pet-test.png',
						price: mainProduct.prices || 0,
						id: mainProduct.id || 0
					}

					// 个性化推荐列表（不包括主推荐产品）
					this.recommendList = relevantProducts.slice(1, 6).map(product => ({
						name: product.tradeName || '推荐产品',
						desc: product.introduction || '适合您宠物的健康产品',
						image: product.picture || '/static/pet-test.png',
						price: product.prices || 0,
						id: product.id || 0
					}))
				} else {
					// 如果没有找到相关产品，使用默认推荐
					this.setDefaultRecommendations(petCategory, ageGroup)
				}
			},
			setDefaultRecommendations(petCategory, ageGroup) {
				// 默认推荐产品
				if (petCategory === 'dog') {
					this.recommendedProduct = {
						name: '宠乐优选 天然无谷成犬粮',
						desc: '无谷物配方，呵护敏感肠胃',
						image: '/static/pet-test.png',
						price: 69.9,
						id: 1
					}

					this.recommendList = [{
							name: '优倍滋 全阶段犬粮',
							desc: '含益生菌，促进消化',
							image: '/static/pet-test.png',
							price: 89.9,
							id: 5
						},
						{
							name: '汪星人 钙片120片',
							desc: '强化骨骼发育',
							image: '/static/pet-test.png',
							price: 65.0,
							id: 7
						}
					]
				} else if (petCategory === 'cat') {
					this.recommendedProduct = {
						name: '健康宠粮 全价冻干猫粮',
						desc: '冻干占比30%，高蛋白低脂',
						image: '/static/pet-test.png',
						price: 79.9,
						id: 3
					}

					this.recommendList = [{
							name: '爱宠世家 幼猫专用羊奶粉',
							desc: '模拟母乳成分，易吸收',
							image: '/static/pet-test.png',
							price: 55.0,
							id: 2
						},
						{
							name: '喵主子 主食猫条',
							desc: '慕斯质地，补水神器',
							image: '/static/pet-test.png',
							price: 45.9,
							id: 6
						}
					]
				} else {
					// 其他宠物通用推荐
					this.recommendedProduct = {
						name: '小宠日记 仓鼠营养粮',
						desc: '科学配比，防挑食',
						image: '/static/pet-test.png',
						price: 25.9,
						id: 10
					}

					this.recommendList = [{
							name: 'AquaPets 热带鱼饲料',
							desc: '增强体色，不浑水',
							image: '/static/pet-test.png',
							price: 19.9,
							id: 11
						},
						{
							name: '小宠日记 仓鼠跑轮',
							desc: '防滑支架安全耐用',
							image: '/static/pet-test.png',
							price: 35.9,
							id: 19
						}
					]
				}
			},
			// 根据状态获取对应的样式类
			getStatusClass(status) {
				switch (status) {
					case '正常':
						return 'status-normal';
					case '已完成':
						return 'status-completed';
					case '需关注':
						return 'status-warning';
					default:
						return '';
				}
			},

			// 查看体检记录详情
			viewRecordDetail(record) {
				uni.navigateTo({
					url: `/pages/health/examination-detail?id=${record.id}`
				});
			},

			// 查看全部体检记录
			navigateToAllRecords() {
				uni.navigateTo({
					url: `/pages/health/examination-list?petId=${this.petInfo.id}`
				});
			},

			// 添加健康日志
			addNewLog() {
				uni.redirectTo({
					url: `/pages/health/add-health-log`
				});
			},

			// 预览图片
			previewImage(images, current) {
				uni.previewImage({
					urls: images,
					current: current
				});
			},

			// 查看产品详情
			viewProductDetail(product) {
				getApp().globalData.currentGoodId = product.id;
				uni.navigateTo({
					url: '/pages/shop/goods'
				});
			},

			// 预约体检
			scheduleExamination() {
				uni.navigateTo({
					url: `/pages/health/schedule-examination?petId=${this.petInfo.id}`
				});
			},

			// 联系兽医
			contactVet() {
				uni.navigateTo({
					url: `/pages/health/contact-vet?petId=${this.petInfo.id}`
				});
			}
		}
	}
</script>

<style scoped>
	.health-detail-container {
		background-color: #f5f5f5;
		padding-bottom: 30rpx;
		min-height: 100vh;
	}

	.header {
		display: flex;
		flex-direction: row-reverse;
		align-items: center;
		background: linear-gradient(to right, #F9CB43, #FFDA7A);
		padding: 60rpx 30rpx;
		border-radius: 0 0 30rpx 30rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
	}

	.back-btn image {
		width: 43rpx;
		height: 40rpx;
		margin-right: 62rpx;
		margin-top: 20rpx;
	}

	.pet-avatar {
		width: 160rpx;
		height: 160rpx;
		border-radius: 100%;
		margin-left: 30rpx;
		border: 6rpx solid #FFFFFF;
		box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
		margin-top: 20rpx;
	}

	.pet-info {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20rpx;
	}

	.pet-name {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
	}

	.pet-detail {
		font-size: 28rpx;
		color: #555;
		background-color: rgba(255, 255, 255, 0.6);
		padding: 6rpx 16rpx;
		border-radius: 20rpx;
		margin-right: 50rpx;
	}

	.section-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
	}

	.title-text {
		font-size: 32rpx;
		font-weight: bold;
		position: relative;
		padding-left: 20rpx;
	}

	.title-text::before {
		content: '';
		position: absolute;
		left: 0;
		top: 10rpx;
		height: 30rpx;
		width: 8rpx;
		background-color: #F9CB43;
		border-radius: 4rpx;
	}

	.more-link,
	.add-log-btn {
		color: #666;
		font-size: 24rpx;
	}

	.add-log-btn {
		color: #F9CB43;
		font-weight: bold;
	}

	.health-overview,
	.examination-record,
	.health-issues,
	.health-logs,
	.recommended-products {
		background-color: white;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 30rpx;
	}

	/* 健康概览部分 */
	.health-metrics {
		display: flex;
		flex-wrap: wrap;
		padding: 0 20rpx 30rpx;
	}

	.metric-item {
		width: 50%;
		display: flex;
		align-items: center;
		padding: 15rpx;
		box-sizing: border-box;
	}

	.metric-icon {
		width: 70rpx;
		height: 70rpx;
		background-color: rgba(249, 203, 67, 0.2);
		border-radius: 35rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 15rpx;
	}

	.metric-content {
		display: flex;
		flex-direction: column;
	}

	.metric-label {
		font-size: 24rpx;
		color: #888;
	}

	.metric-value {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
	}

	/* 体检记录部分 */
	.record-list {
		padding: 0 30rpx 30rpx;
	}

	.record-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: #f9f9f9;
		border-radius: 16rpx;
		margin-bottom: 15rpx;
		position: relative;
	}

	.record-date {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-right: 20rpx;
		min-width: 60rpx;
	}

	.date-day {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
	}

	.date-month {
		font-size: 24rpx;
		color: #888;
	}

	.record-content {
		flex: 1;
	}

	.record-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 6rpx;
		display: block;
	}

	.record-hospital {
		font-size: 24rpx;
		color: #888;
		display: block;
		margin-bottom: 6rpx;
	}

	.record-status {
		display: inline-block;
		font-size: 22rpx;
		padding: 4rpx 12rpx;
		border-radius: 10rpx;
	}

	.status-normal {
		background-color: #E8F5E9;
		color: #4CAF50;
	}

	.status-completed {
		background-color: #E3F2FD;
		color: #2196F3;
	}

	.status-warning {
		background-color: #FFF3E0;
		color: #FF9800;
	}

	.record-arrow {
		font-size: 24rpx;
		color: #ccc;
	}

	/* 健康问题部分 */
	.issues-list {
		padding: 0 30rpx 30rpx;
	}

	.issue-item {
		display: flex;
		background-color: #f9f9f9;
		border-radius: 16rpx;
		padding: 20rpx;
		margin-bottom: 15rpx;
	}

	.issue-tag {
		min-width: 60rpx;
		height: 60rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 10rpx;
		margin-right: 20rpx;
		font-size: 24rpx;
		color: white;
	}

	.issue-content {
		flex: 1;
	}

	.issue-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 8rpx;
		display: block;
	}

	.issue-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 10rpx;
		display: block;
	}

	.issue-solution {
		margin-top: 10rpx;
	}

	.solution-title {
		font-size: 24rpx;
		color: #888;
		margin-bottom: 8rpx;
		display: block;
	}

	.solution-tags {
		display: flex;
		flex-wrap: wrap;
	}

	.solution-tag {
		font-size: 22rpx;
		background-color: #F0F0F0;
		padding: 4rpx 12rpx;
		border-radius: 10rpx;
		margin-right: 10rpx;
		margin-bottom: 6rpx;
		color: #666;
	}

	/* 健康日志部分 */
	.log-timeline {
		padding: 0 30rpx 20rpx;
	}

	.log-item {
		position: relative;
		padding-left: 30rpx;
		margin-bottom: 30rpx;
	}

	.log-item::before {
		content: '';
		position: absolute;
		left: 10rpx;
		top: 30rpx;
		height: calc(100% + 30rpx);
		width: 2rpx;
		background-color: #eee;
	}

	.log-item:last-child::before {
		display: none;
	}

	.log-time {
		font-size: 24rpx;
		color: #888;
		margin-bottom: 10rpx;
		position: relative;
	}

	.log-time::before {
		content: '';
		position: absolute;
		left: -30rpx;
		top: 10rpx;
		width: 20rpx;
		height: 20rpx;
		border-radius: 50%;
		background-color: #F9CB43;
	}

	.log-content {
		background-color: #f9f9f9;
		border-radius: 16rpx;
		padding: 15rpx;
	}

	.log-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 6rpx;
		display: block;
	}

	.log-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 10rpx;
		display: block;
	}

	.log-images {
		display: flex;
		flex-wrap: wrap;
		margin-top: 10rpx;
	}

	.log-image {
		width: 150rpx;
		height: 150rpx;
		border-radius: 10rpx;
		margin-right: 10rpx;
		margin-bottom: 10rpx;
	}

	/* 推荐产品部分 */
	.products-scroll {
		white-space: nowrap;
		width: 650rpx;
		padding: 0 0 30rpx;
		margin-left: 30rpx;
	}

	.products-scroll-content {
		display: inline-flex;
	}

	.product-item {
		display: inline-block;
		width: 250rpx;
		margin-right: 20rpx;
		background-color: #f9f9f9;
		border-radius: 16rpx;
		padding: 15rpx;
		position: relative;
	}

	.product-image {
		width: 220rpx;
		height: 220rpx;
		border-radius: 12rpx;
		margin-bottom: 10rpx;
	}

	.product-name {
		font-size: 26rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 6rpx;
		white-space: normal;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	.product-reason {
		font-size: 22rpx;
		color: #F9CB43;
		margin-bottom: 6rpx;
		white-space: normal;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	.product-price {
		font-size: 26rpx;
		font-weight: bold;
		color: #FF6B35;
		margin-top: 10rpx;
	}

	.product-buy-btn {
		position: absolute;
		right: 15rpx;
		bottom: 15rpx;
		background-color: #F9CB43;
		color: white;
		font-size: 22rpx;
		padding: 4rpx 12rpx;
		border-radius: 20rpx;
	}

	/* 操作按钮 */
	.action-buttons {
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		margin-top: 20rpx;
	}

	.action-btn {
		width: 48%;
		height: 90rpx;
		border-radius: 45rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
	}

	.primary-btn {
		background-color: #F9CB43;
		color: white;
	}

	.secondary-btn {
		background-color: white;
		color: #F9CB43;
		border: 2rpx solid #F9CB43;
	}

	.action-btn text {
		margin-left: 10rpx;
	}

	.bottom-space {
		height: 100rpx;
	}

	.iconfont {
		width: 40rpx;
		height: 40rpx;
	}
</style>